package com.matrix.draft.sockettest.day9;


import com.matrix.draft.sockettest.day9.pojo.GlobalProto;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class MultiProtoServerHandler extends SimpleChannelInboundHandler<GlobalProto.Global> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GlobalProto.Global msg) {
        switch (msg.getJavaType()) {
            case Chocolate:
                System.out.println("Server receiving: "+msg.getChocolate().getName());
                break;
            case Milk:
                System.out.println("Server receiving: "+msg.getMilk().getName());
                break;
            case Banana:
                System.out.println("Server receiving: "+msg.getBanana().getName());
                break;
        }
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        ctx.close();
    }
}
